from django.db import models
from django.contrib import admin

# Create your models here.
class Album(models.Model):
    name = models.CharField(max_length=250)
    description = models.TextField()
    
    class Meta:
        ordering = ['name']
    
    def __unicode__(self):
        return self.name
    
    
class Photo(models.Model):
    album = models.ForeignKey(Album)
    title = models.CharField(max_length=100)
    image = models.ImageField(upload_to='photos')
    caption = models.CharField(max_length=250, blank=True)
    
    
    class Meta:
        ordering = ['title']
        
    def __unicode__(self):
        return self.title
    
class PhotoInline(admin.StackedInline):
    model = Photo

class AlbumAdmin(admin.ModelAdmin):
    inlines = [PhotoInline]
    
admin.site.register(Album, AlbumAdmin)
admin.site.register(Photo)